import 'dart:convert';

import 'package:flutter_test/flutter_test.dart';
import 'package:im_app/im/dao/ImMessageDao.dart';
import 'package:im_app/im/pojo/ImPojo.dart';
import 'package:im_app/im/util/DbUtil.dart';
import 'package:im_app/im/util/ImSingleton.dart';
import 'package:sqflite_common_ffi/sqflite_ffi.dart';

void main() {

  test("insert message", () async {
    sqfliteFfiInit();
    databaseFactory = databaseFactoryFfi;
    Database database = await DbUtil.connect("imtest.db");
    ImSingleton.getInstance()?.dataBase = database;

    var messageDao = new ImMessageDao();
    var message = new ImMessage(fromUserId: 'u001', content: 'u001', messageType: ImMessageType.Text);
    String? seq = ImSingleton.getInstance().seqCreator.create();
    message.currentUserId = 'test00100';
    message.clientId = seq;
    message.status = ImMessageStatus.none;
    await messageDao.batchInserts([message]);
    database.close();
  });

  test("get message", () async {
    sqfliteFfiInit();
    databaseFactory = databaseFactoryFfi;
    Database database = await DbUtil.connect("imtest.db");

    List list = await database.query("im_message");
    print("db setting : " + jsonEncode(list) + ", " + list.length.toString());
  });
}